// pages/user/user/userPurchase/userPurchase.js
const app = getApp();
import Api from "../../../../utils/http";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    order_number: '', //订单号
    pay_price: '', //订单金额
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log(options)
    that.setData({
      order_number: options.order_number,
      pay_price: options.pay_price
    })
    // that.getSureBuy();
  },
  //获取订单信息
  // getSureBuy:function(){
  //   var that=this;
  //   let uid=wx.getStorageSync('userid')
  //   var param={
  //     uid:uid.uid,
  //     pay_num:that.data.order_number
  //   }
  //   console.log(param)
  //   Api.ajax('/app/Zcapital/sureBuy',param).then(res=>{
  //     console.log(res)
  //     if (res.code==200) {
  //       that.setData({
  //         sureBuy:res.data
  //       })
  //     }
  //   })
  // },
  //微信支付
  addclickwxpay: function () {
    var that = this;
    var param = {
      order_number: that.data.order_number,
      pay_type: 2,
    }
    console.log(param)
    Api.ajax('/app/Zcapital/pay', param).then(res => {
      console.log(res)
      if (res.code == 200) {
        wx.requestPayment({
          timeStamp: res.data.timestamp.toString(),
          nonceStr: res.data.nonce_str,
          package: 'prepay_id=' + res.data.prepay_id,
          signType: 'MD5',
          paySign: res.data.sign,
          success(res) {
            wx.showToast({
              title: '支付成功',
              icon: 'success',
              duration: 1000
            });
            setTimeout(function () {
              wx.navigateBack({
                delta: 2
              })
            }, 1000);
          }
        })

      }
    })
  },
  // 
  //余额支付
  addclickyepay: function () {
    var that = this;
    var param = {
      order_number: that.data.order_number,
      pay_type: 1,
    }
    console.log(param)
    Api.ajax('/app/Zcapital/pay', param).then(res => {
      console.log(res)
      if (res.code == 200) {
        wx.redirectTo({
          url: '/pages/user/user/userRecycling/userRecycling',
        });
      } else {
        wx.showToast({
          title: '余额不足',
          icon: 'none',
          duration: 2000
        })
      }
    })

  },
  // getpay
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})